export default function (config) {
  const { data } = config
  return {
    title: {
      text: config.centerValue,
      subtext: config.centerText,
      textStyle: {
        color: config.color,
        fontSize: 20
      },
      subtextStyle: {
        color: '#222'
      },
      textAlign: 'center',
      left: '26%',
      top: '36%'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      itemWidth: 10,
      itemHeight: 10,
      selectedMode: false,
      formatter: (name) => {
        return name + ' ' + data.find((item) => item.name === name).value
      },
      top: 'center',
      right: '5%'
    },
    series: [
      {
        type: 'pie',
        right: '45%',
        // 内环外环
        radius: ['60%', '70%'],
        emphasis: {
          disabled: true
        },
        data: formatData(data)
      }
    ]
  }
}
const formatData = (data) => {
  return data.map((item) => {
    return {
      name: item.name,
      value: item.value,
      label: {
        show: false
      },
      itemStyle: { color: item.color }
    }
  })
}
